package com.chapter_1;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * @Author: Timo
 * @Date: 2019/5/10 11:24
 * @Description: 类用途：
 */
public class MyCallableThread implements  Callable<List<User>> {

    private List<User> users;
    private Integer startNum;

    public MyCallableThread() {
        setUsers();
    }

    public MyCallableThread(List<User> users) {
        this.users = users;
    }

    public MyCallableThread(Integer startNum) {
        this.startNum = startNum;
        setUsers();

    }

    @Override
    public List<User> call() throws Exception {
        if (startNum == 3) {
            Thread.sleep(10_000);
        }
        System.out.println("任务["+startNum+"]开始执行");
        return this.users;
    }

    private void setUsers() {
//        System.out.println(Thread.currentThread().getName()+" .. "+startNum+" 开始执行了=============");
        if (startNum != null && startNum > 0) {
            users = new ArrayList<User>(5);

            for (int i = startNum * 10; i < (startNum * 10 + startNum); i++) {
                users.add(new User(i, "timo"+i));
            }
        }else {
            users = new ArrayList<User>(5);
            users.add(new User(1, "timo1"));
            users.add(new User(2, "timo2"));
            users.add(new User(3, "timo3"));
            users.add(new User(4, "timo4"));
            users.add(new User(5, "timo5"));
        }

    }


}
